using System;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
namespace BMC.ARSystem
{
	[ClassInterface, Guid("19ecd9ad-2b21-4e72-adcd-22b0b5de9921"), ProgId("BMC.ARSystem.PackingList")]
	public class PackingList : Container
	{
		private static ExternalReference _actLinkGuideIndicator = new ExternalReference(32783);
		private static ExternalReference _appIndicator = new ExternalReference(32784);
		private static ExternalReference _conIndicator = new ExternalReference(6);
		private static ExternalReference _filterGuideIndicator = new ExternalReference(32793);
		private static ExternalReference _packListIndicator = new ExternalReference(32785);
		private static ExternalReference _websvcIndicator = new ExternalReference(32801);
		private ArrayList _items;
		public ArrayList Items
		{
			get
			{
				return this._items;
			}
			set
			{
				this._items = value;
			}
		}
		public PackingList()
		{
			this.Initialize();
		}
		internal PackingList(object[] rawData, Server server) : base(rawData, server)
		{
			this.Initialize();
			this.LoadRefs(server);
		}
		private void Initialize()
		{
			this._items = new ArrayList();
		}
		internal void LoadRefs(Server server)
		{
			PackingListItem.ObjectType objectType = PackingListItem.ObjectType.Unknown;
			int i = 0;
			int count = this._references.get_Count();
			while (i < count)
			{
				Reference reference = this._references.get_Item(i) as Reference;
				if (reference != null)
				{
					int referenceType = reference.ReferenceType;
					if (referenceType != 6)
					{
						switch (referenceType)
						{
						case 32783:
							objectType = PackingListItem.ObjectType.ActLinkGuide;
							goto IL_118;
						case 32784:
							objectType = PackingListItem.ObjectType.Application;
							goto IL_118;
						case 32785:
							objectType = PackingListItem.ObjectType.PackingList;
							goto IL_118;
						case 32786:
						case 32787:
						case 32792:
							this._items.Add(new PackingListItem((PackingListItem.ObjectType)reference.ReferenceType, reference.Label));
							goto IL_118;
						case 32788:
						case 32789:
						case 32790:
						case 32791:
							break;
						case 32793:
							objectType = PackingListItem.ObjectType.FilterGuide;
							goto IL_118;
						default:
							if (referenceType == 32801)
							{
								objectType = PackingListItem.ObjectType.WebService;
								goto IL_118;
							}
							break;
						}
						this._items.Add(new PackingListItem((PackingListItem.ObjectType)reference.ReferenceType, reference.Name));
					}
					else
					{
						if (reference.Name != null && reference.Name.get_Length() > 0)
						{
							this._items.Add(new PackingListItem(objectType, reference.Name));
						}
					}
				}
				IL_118:
				i++;
			}
		}
		internal void SaveRefs(Server server)
		{
			base.MembersModified = new BitVector32(base.MembersModified.get_Data() | 256);
			this._references.Clear();
			base.AddItem(PackingList._actLinkGuideIndicator);
			base.AddItem(PackingList._appIndicator);
			base.AddItem(PackingList._conIndicator);
			base.AddItem(PackingList._filterGuideIndicator);
			base.AddItem(PackingList._packListIndicator);
			base.AddItem(PackingList._websvcIndicator);
			IEnumerator enumerator = this._items.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					PackingListItem packingListItem = (PackingListItem)enumerator.get_Current();
					if (packingListItem.Type == PackingListItem.ObjectType.ActLinkGuide || packingListItem.Type == PackingListItem.ObjectType.Application || packingListItem.Type == PackingListItem.ObjectType.FilterGuide || packingListItem.Type == PackingListItem.ObjectType.PackingList || packingListItem.Type == PackingListItem.ObjectType.WebService)
					{
						Reference reference = new Reference(6, packingListItem.Name);
						this._references.Insert(this.GetInsertionOffset((int)packingListItem.Type), reference);
					}
					else
					{
						if (packingListItem.Type == PackingListItem.ObjectType.DistributedMapping || packingListItem.Type == PackingListItem.ObjectType.DistributedPool || packingListItem.Type == PackingListItem.ObjectType.GroupData)
						{
							base.AddItem(new ExternalReference((int)packingListItem.Type)
							{
								Label = packingListItem.Name
							});
						}
						else
						{
							Reference reference = new Reference((int)packingListItem.Type, packingListItem.Name);
							base.AddItem(reference);
						}
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
		}
		private int GetInsertionOffset(int typ)
		{
			int num = -1;
			if (typ == PackingList._actLinkGuideIndicator.ReferenceType)
			{
				num = this._references.IndexOf(PackingList._actLinkGuideIndicator);
			}
			else
			{
				if (typ == PackingList._appIndicator.ReferenceType)
				{
					num = this._references.IndexOf(PackingList._appIndicator);
				}
				else
				{
					if (typ == PackingList._filterGuideIndicator.ReferenceType)
					{
						num = this._references.IndexOf(PackingList._filterGuideIndicator);
					}
					else
					{
						if (typ == PackingList._packListIndicator.ReferenceType)
						{
							num = this._references.IndexOf(PackingList._packListIndicator);
						}
						else
						{
							if (typ == PackingList._websvcIndicator.ReferenceType)
							{
								num = this._references.IndexOf(PackingList._websvcIndicator);
							}
						}
					}
				}
			}
			return num + 1;
		}
		public void AddItem(PackingListItem item)
		{
			base.MembersModified = new BitVector32(base.MembersModified.get_Data() | 256);
			this._items.Add(item);
		}
		public void RemoveItem(PackingListItem item)
		{
			base.MembersModified = new BitVector32(base.MembersModified.get_Data() | 256);
			this._items.Remove(item);
		}
	}
}
